package com.itheima.reggie.controller;


import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.vo.SetmealDto;
import com.itheima.reggie.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;


    @GetMapping("list")
    public R getSetmealsByCategoryId(Long categoryId,Integer status){
        return setmealService.getSetmealsByCategoryId(categoryId,status);
    }
    @PutMapping
    public R updateSetmeal(@RequestBody SetmealDto setmealDto) {
        return setmealService.updateSetmeal(setmealDto);
    }

    //修改回显
    @GetMapping("/{id}")
    public R selectSetmealById(@PathVariable Long id) {
        return setmealService.selectSetmealById(id);
    }

    //启用禁用
    @PostMapping("/status/{status}")
    public R updateSetmealStatus(@PathVariable Integer status, @RequestParam("ids") List<Long> ids) {
        return setmealService.updateSetmealStatus(status, ids);
    }

    //删除套餐
    @DeleteMapping
    public R deleteSetmeal(@RequestParam("ids") List<Long> ids) {
        return setmealService.deleteSetmeal(ids);
    }

    //新增套餐
    @PostMapping
    public R saveSetmeal(@RequestBody SetmealDto setmealDto) {
        return setmealService.saveSetmeal(setmealDto);
    }

    //套餐分页
    @GetMapping("/page")
    public R pageSetmeal(Integer page, Integer pageSize, String name) {
        return setmealService.pageSetmeal(page, pageSize, name);
    }

}
